package org.zanpu.metadataserver.core.dbmanager;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * Created by MD on 2016/10/26.
 */
public class DynamicDataSource extends AbstractRoutingDataSource {

    private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();

    public static String getCurrentLookupKey() {
        return contextHolder.get().toString();
    }

    public static void setCurrentLookupKey(String currentLookupKey) {

        contextHolder.set(currentLookupKey);
    }

    @Override
    protected Object determineCurrentLookupKey() {
        return getCurrentLookupKey();
    }
}
